#!/usr/bin/env bash
# 参考页面：https://www.jianshu.com/p/824912d9afda
yum install -y python-pip
pip install -y shadowsocks
mkdir /etc/shadowsocks
cat >/etc/shadowsocks/shadowsocks.example.json<<EOF
{
    "server":"x.x.x.x",  # Shadowsocks服务器地址
    "server_port":1035,  # Shadowsocks服务器端口
    "local_address": "127.0.0.1", # 本地IP
    "local_port":1080,  # 本地端口
    "password":"password", # Shadowsocks连接密码
    "timeout":300,  # 等待超时时间
    "method":"aes-256-cfb",  # 加密方式
    "fast_open": false,  # true或false。开启fast_open以降低延迟，但要求Linux内核在3.7+
    "workers": 1  #工作线程数
}
EOF
cat >/usr/lib/systemd/system/shadowsocks.service<<EOF
[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/sslocal -c /etc/shadowsocks/shadowsocks.json
[Install]
WantedBy=multi-user.target
EOF
yum install privoxy -y
echo "forward-socks5t / 127.0.0.1:1080 .">>/etc/privoxy/config

cat >/usr/lib/systemd/system/ssproxy.service<<EOF
[Unit]
Description=Ssproxy
[Service]
TimeoutStartSec=0
ExecStart=systemctl start shadowsocks && systemctl start privoxy
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
